package org.apache.doris.demo.spring.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.doris.demo.spring.mapper.TagMapper;
import org.apache.doris.demo.spring.model.Tag;
import org.apache.doris.demo.spring.service.TagService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

@Service
public class TagServiceImpl extends ServiceImpl<TagMapper, Tag> implements TagService {
    @Override
    public Map<String, Object> DataCount() {
        return baseMapper.DataCount();
    }

    @Override
    public List<Map<String, Object>> getremen() {
        return baseMapper.getremen();
    }


@Override
    public List<Map<String, Object>> getpaihang() {
        return baseMapper.getpaihang();
    }

    @Override
    public List<Tag> searchTagsByKeyword(String keyword) {
        QueryWrapper<Tag> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("tag_type", keyword).or().like("tag_name",keyword);
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public Map<String, Set<String>> getTagTypeMap() {
        List<Tag> tags = baseMapper.selectList(null);
        Map<String, Set<String>> map = tags.stream()
                .collect(Collectors.groupingBy(Tag::getTagType, Collectors.mapping(Tag::getTagName, Collectors.toSet())));
        return map;
    }

}
